package com.crane.oss.web.controller.school;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.crane.common.core.dto.MultiResponse;
import com.crane.common.core.dto.Response;
import com.crane.common.core.dto.SingleResponse;
import com.crane.oss.school.bean.request.QueryTeacherCycleReq;
import com.crane.oss.school.bean.request.teachercycle.AddTeacherCycleReq;
import com.crane.oss.school.bean.request.teachercycle.UpdateTeacherCycleReq;
import com.crane.oss.school.bean.resp.TeacherCycleResp;
import com.crane.oss.school.service.TeacherCycleService;
import com.crane.oss.web.BaseBusinessController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;


/**
 * @author zhenxing.pi
 * @email ccsu123456@qq.com
 * @date 2022年03月26日 14时24分54秒
 */

@Api(value = "TeacherCycleController", tags = {"教学周期表"})
@RestController
@RequestMapping("/school/teacherCycle")
public class TeacherCycleController extends BaseBusinessController {

    @Autowired
    TeacherCycleService teacherCycleService;


    @ApiOperation(value = "获取列表信息", notes = "获取列表信息")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryTeacherCycleReq")
    @RequiresPermissions("school:teachercycle:list")
    @PostMapping("/list")
    public MultiResponse<TeacherCycleResp> list(@RequestBody QueryTeacherCycleReq request) {
        request.setPartyId(getPartyId());
        IPage<TeacherCycleResp> page = teacherCycleService.queryList(request);
        return MultiResponse.of(page.getRecords(), (int) page.getTotal(), request);
    }


    @ApiOperation(value = "获取详细信息", notes = "获取详细信息")
    @ApiImplicitParam(name = "id", value = "请求对象", paramType = "path", dataType = "Long")
    @RequiresPermissions("school:teachercycle:info")
    @GetMapping("/info/{id}")
    public SingleResponse<TeacherCycleResp> info(@PathVariable("id") Long id) {
        TeacherCycleResp teacherCycleResp = teacherCycleService.queryTeacherCycle(id);
        return SingleResponse.of(teacherCycleResp);
    }


    @ApiOperation(value = "新增", notes = "获取新增信息")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "AddTeacherCycleReq")
    @RequiresPermissions("school:teachercycle:save")
    @PostMapping("/save")
    public Response save(@RequestBody @Valid AddTeacherCycleReq request) {
        request.setPartyId(getPartyId());
        request.setCreateUserId(getUserId());
        request.setCreateTime(new Date());
        int count = teacherCycleService.save(request);
        return Response.buildSuccess();
    }

    @ApiOperation(value = "修改", notes = "修改")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "UpdateTeacherCycleReq")
    @RequiresPermissions("school:teachercycle:update")
    @PostMapping("/update")
    public Response update(@RequestBody @Valid UpdateTeacherCycleReq request) {
        request.setPartyId(getPartyId());
        int count = teacherCycleService.update(request);
        return Response.buildSuccess();
    }

    @ApiOperation(value = "删除", notes = "删除")
    @ApiImplicitParam(name = "id", value = "请求对象", paramType = "path", dataType = "Long")
    @RequiresPermissions("school:teachercycle:delete")
    @GetMapping("/delete/{id}")
    public Response delete(@PathVariable("id") Long id) {
        int count = teacherCycleService.delete(id,getPartyId());
        return Response.buildSuccess();
    }


}
